package com.lyc.ssm.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect//声明切面类
public class StudentAspect {

    //声明切点
    @Pointcut(value = "execution(* com.lyc.ssm.service.impl.*.*(..))")
    public void pointCut() {
    }

//    //前置通知
//    @Before(value = "pointCut()")
//    public void before(JoinPoint joinPoint){//JoinPoint 连接点，拦截的方法
//        System.out.println("aop before:"+joinPoint.getArgs().toString());//输出方法的所有参数
//    }
//
//    //后置通知
//    @After(value = "pointCut()")
//    public void after(JoinPoint joinPoint){
//        System.out.println("aop after:"+joinPoint.getSignature().getName());//输出方法名
//    }

    //    环绕通知
    @Around(value = "pointCut()")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) {//如果拦截方法有返回值则不能使用void修饰返回值类型
        try {
            System.out.println(proceedingJoinPoint.getSignature().getName());
            Object result = proceedingJoinPoint.proceed();//执行拦截方法
            System.out.println(proceedingJoinPoint.getArgs().toString());
            return result;
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            return null;
        }
    }
}
